<template>
	<view>
		<!-- 未登录 -->
		<template v-if="!loginStuatus">
			<view class="text-center px-2 font-md py-4" >登录社区，体验更多功能</view>
			<view>
				<otherLogin></otherLogin>
			</view>
			<view class="text-light-muted text-center" @click="openLogin">
				账号/邮箱/手机号登录<text class="iconfont icon-jinru ml-1 py-4"></text>
			</view>
		</template>
			<view class="flex p-2 align-center" v-else>
				<image :src="avtar" style="width: 100rpx; height: 100rpx;" class="rounded-circle"></image>
				<view class="flex flex-column flex-1 px-2">
					<text class="font-md text-dark font-weight-bold">{{user.username}}</text>
					<text class="text-muted font mt-1">总帖子{{myData[0].num}}  今日发帖{{myData[1].num}}</text>
				</view>
				<text class="iconfont icon-jinru "></text>
			</view>
		<view class="flex px-3 py-3 ">
			<view class="flex-1 flex  flex-column justify-center align-center" v-for="(item,index) in myData" >
				<text class="font-md font-weight-bold">{{item.num}}</text>
				<text class="text-muted">{{item.name}}</text>
			</view>
		</view>
		<view class="px-3 px-2">
			<image src="../../static/common/banner1.jpg" class="rounded" mode="aspectFill" style="height: 170rpx; width: 100%;"></image>
		</view>
		<view class="">
			
		</view>
		<uni-list-item showExtraIcon link showArrow title="浏览历史" @click="openHistory">
			<text class="iconfont icon-liulan"></text>
		</uni-list-item > 	
		<uni-list-item showExtraIcon showArrow title="社区认证">
			<text class="iconfont icon-huiyuanvip"></text>
		</uni-list-item > 	
		<uni-list-item showExtraIcon showArrow title="审核帖子">
			<text class="iconfont icon-keyboard"></text>
		</uni-list-item > 	
		<!-- #ifndef APP-PLUS -->
		<uni-list-item showExtraIcon showArrow link title="设置" @click="openSet">
			<text class="iconfont icon-shezhi"></text>
		</uni-list-item > 
		<!-- #endif -->
		
	</view>
</template>

<script>
	import uniListItem from '@/components/uni-ui/uni-list-item/uni-list-item.vue'
	import otherLogin from '@/components/common/other-login.vue'
	import { mapState } from 'vuex'
	export default {
		components:{
			uniListItem,
			otherLogin
		},
		data() {
			return {
				myData:[
					{
						num:0,
						name:"帖子"
					},
					{
						num:0,
						name:"动态"
					},
					{
						num:0,
						name:"评论"
					},
					{
						num:0,
						name:"粉丝"
					}
				]
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url:'../user-set/user-set'
			})
		},
		onShow() {
			if(this.loginStuatus){
				this.getData()
			}
		},
		computed:{
			...mapState({
				loginStuatus:state => state.loginStuatus,
				user:state => state.userinfo,
			}),
			//设置默认头像
			avtar(){
				return this.user.userpic ? this.user.userpic :'/static/default.jpg'
			}
		},
		watch: {
			loginStuatus(newValue, oldValue) {
				if(newValue){
					this.getData()
				} else {
					this.myData.forEach(item=>{
						item.num = 0
					})
				}
			}
		},
		methods: {
			openLogin(){
				uni.navigateTo({
					url: '../login/login',
				});
			},
			openHistory(){
				uni.navigateTo({
					url: '../history/history',
				});
			},
			// #ifndef APP-PLUS
			openSet(){
				// uni.navigateTo({
				// 	url: '../user-set/user-set',
				// 	success: res => {},
				// 	fail: () => {},
				// 	complete: () => {}
				// });
				this.navigateTo({
					url:'../user-set/user-set'
				})
			},
			// #endif
			getData(){
				this.$H.get('/user/getcounts/'+this.user.id,{},{
					token:true,
				}).then(res => {
					this.myData[0].num = res.post_count
					this.myData[1].num = res.today_posts_count
					this.myData[2].num = res.comments_count
					this.myData[3].num = res.withfen_count
				})
			}
		}
	}
</script>

<style>

</style>
